package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.StrategyComments;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCommentsService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 攻略点评的评论
 */
@RestController
@RequestMapping("/CommentStrategies")
public class StrategyCommentsController {

    @Autowired
    private IStrategyCommentsService commentsService;

    @GetMapping("/{strategyCommentId}")
    public PageInfo<StrategyComments> query(StrategyCommentQueryObject qo) {
        qo.setOrderBy("commentTime");
        return commentsService.query(qo);
    }

    @PostMapping
    public JsonResult save(StrategyComments comments) {
        JsonResult jsonResult = new JsonResult();
        try {
            commentsService.save(comments);
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.mark("操作异常");
        }
        return jsonResult;
    }

}
